package com.yby.es.controller;

import com.alibaba.fastjson.JSONObject;
import com.yby.es.entity.User;
import com.yby.es.producer.RabbitMQProducer;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbit")
@RequiredArgsConstructor
public class RabbitMqController {

    private final RabbitMQProducer rabbitMQProducer;

    @GetMapping("/sendMQ")
    public void sendMQ(@RequestParam("name") String name){
        User user = new User();
        user.setId(1L);
        user.setSex("男");
        user.setName("元宇宙");
        user.setAge(11);
        rabbitMQProducer.sendMessage(JSONObject.toJSONString(user));
    }
}
